import {useUserStore} from "@/stores/user.js"
export function getUser(){
	console.log(222)
	const userStore = useUserStore()
	if(Object.keys(userStore.userInfo).length>0){
		return userStore.userInfo
	}else{
		return uni.getStorageSync("userInfo")
	}
	
}

export function setUser(user){
	uni.setStorageSync("userInfo",user)
	
}
export function clearUser(){
	uni.removeStorageSync("userInfo")
	const userStore = useUserStore()
	userStore.userInfo = {}
	uni.showToast({
		title:"退出成功",
		icon:"success",
		duration:3000,
		success() {
			uni.reLaunch({
				url:"/pages/index/index"
			})
		}			
	})
}
export function checkUserRedirect(user){
	if(!user.id){
		uni.showToast({
			icon:"none",
			title:"请先登录！",
			duration:3000,
			success() {
				uni.navigateTo({
					url:"/wuLian/pages/login"
				})
			}
		})
	}
}